package org.example.types.design.link;


import lombok.Getter;

/**
 * @author yinghuashen
 * @version 1.0
 * @description
 * @date 2025/3/7 23:44
 */

public class AbstractLogicLink<T, D, R>{

    @Getter
    private int size = 0;

    private final AbstractLogicLinkNode<T, D, R> head;

    public AbstractLogicLink(AbstractLogicLinkNode<T, D, R>... nodes) {
        head = new AbstractLogicLinkNode<T, D, R>() {
            @Override
            public R execute(T t, D d) {
                return executeNext(t, d);
            }
        };

        AbstractLogicLinkNode<T, D, R> tail = head;
        for (AbstractLogicLinkNode<T, D, R> node : nodes) {
            tail = tail.setNext(node);
            ++size;
        }
    }

    public AbstractLogicLinkNode<T, D, R> getLogicLink() {
        return head.getNext();
    }
}
